<template>
  <div class="tab-control">
    <div v-for="(item,index) in titles"
         class="tab-control-item"
         :class="{active : index === currentIndex}"
         @click="itemClick(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: "TabControl",
    data(){
      return{
        currentIndex: 0
      }
    },
    props: {
      titles: {
        type: Array,
        default(){
          return []
        }
      }
    },
    methods: {
      itemClick(index) {
        //把当前index赋值给currentIndex
        this.currentIndex = index
        //把index发送给父组件
        this.$emit('tabClick',index)
      }
    }
  }
</script>

<style scoped>
.tab-control {
  display: flex;
  text-align: center;
  font-size: 16px;
  height: 40px;
  width: 100%;
  line-height: 44px;
  /*padding-bottom: 44px;*/
}
  .tab-control-item{
    flex: 1;
    text-align: center;
  }
  .tab-control-item span{
    padding: 5px;
  }
  .active{
    color: #ff8198;

  }
  .active span{
    border-bottom: 3px solid #ff8198;
  }
</style>
